//
// Created by Kai Wang on 2023/12/28.
//
#include <customer/customer_member_rank.h>


float get_discount(MemberRank rank)
{
    switch(rank)
    {
    case MemberRank::NOT_MEMBER:
        return 1.0;
    case MemberRank::PRIMARY_MEMBER:
        return 0.95;
    case MemberRank::INTERMEDIATE_MEMBER:
        return 0.85;
    case MemberRank::ADVANCED_MEMBER:
        return 0.75;
    default:
        return 1.0;
    }
}

MemberRank get_rank_from_consumption(float consumption)
{
    if(consumption < 20)
    {
        return MemberRank::NOT_MEMBER;
    }
    else if(consumption < 50)
    {
        return MemberRank::PRIMARY_MEMBER;
    }
    else if(consumption < 100)
    {
        return MemberRank::INTERMEDIATE_MEMBER;
    }
    else
    {
        return MemberRank::ADVANCED_MEMBER;
    }
}

namespace Convert
{
void String2MemberRank(const std::string &str, MemberRank &rank)
{
    if(str == "NOT_MEMBER")
    {
        rank = MemberRank::NOT_MEMBER;
    }
    else if(str == "PRIMARY_MEMBER")
    {
        rank = MemberRank::PRIMARY_MEMBER;
    }
    else if(str == "INTERMEDIATE_MEMBER")
    {
        rank = MemberRank::INTERMEDIATE_MEMBER;
    }
    else if(str == "ADVANCED_MEMBER")
    {
        rank = MemberRank::ADVANCED_MEMBER;
    }
    else
    {
        rank = MemberRank::NOT_MEMBER;
    }
}

void MemberRank2String(const MemberRank &rank, std::string &str)
{
    switch(rank)
    {
    case MemberRank::NOT_MEMBER:
        str = "NOT_MEMBER";
        break;
    case MemberRank::PRIMARY_MEMBER:
        str = "PRIMARY_MEMBER";
        break;
    case MemberRank::INTERMEDIATE_MEMBER:
        str = "INTERMEDIATE_MEMBER";
        break;
    case MemberRank::ADVANCED_MEMBER:
        str = "ADVANCED_MEMBER";
        break;
    default:
        str = "NOT_MEMBER";
        break;
    }
}

std::string MemberRank2String(const MemberRank &rank)
{
    std::string str;
    switch(rank)
    {
    case MemberRank::NOT_MEMBER:
        str = "NOT_MEMBER";
        break;
    case MemberRank::PRIMARY_MEMBER:
        str = "PRIMARY_MEMBER";
        break;
    case MemberRank::INTERMEDIATE_MEMBER:
        str = "INTERMEDIATE_MEMBER";
        break;
    case MemberRank::ADVANCED_MEMBER:
        str = "ADVANCED_MEMBER";
        break;
    default:
        str = "NOT_MEMBER";
        break;
    }
    return str;
}
}